package com.powernode.controller;


import com.github.pagehelper.PageInfo;
import com.powernode.common.Result;
import com.powernode.domain.VisitLog;
import com.powernode.dto.visitLogDto;
import com.powernode.service.impl.VisitLogService;
import com.powernode.utils.WebMVCUtils;
import jdk.nashorn.internal.ir.RuntimeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//@RestController相当于两个注解
@RestController
@RequestMapping("visitLog")
public class VisitLogController {
    @Autowired
    VisitLogService visitLogService;


    //添加拜访数据数据
    @RequestMapping("addVisitLog.do")
    public Result addVisitLog(VisitLog visitLog) {
        try {
            //设置用户id与用户姓名
            visitLog.setUserId(WebMVCUtils.getCurrentUser().getId());
            visitLog.setRealname(WebMVCUtils.getCurrentUser().getRealname());
            //保存
            this.visitLogService.insertSelective(visitLog);
            return Result.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ADD_ERROR;
        }
    }


    //更据客户id查询当前客户的拜访记录

    @RequestMapping("listVisitLogByCustomerId.do")
    public Result listVisitLogByCustomerId(visitLogDto visitLogDto) {

      //  System.out.println(visitLogDto+"----------"+"哈啊啊哈");

        PageInfo<VisitLog> pageInfo = this.visitLogService.listVisitLogByCustomerId(visitLogDto);

        return new Result(0, "查询成功", pageInfo.getTotal(), pageInfo.getList());

    }
}